<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 商品模型
 *
 * @author Miluo Huang
 *
 * @SWG\Model(id="Goods")
 */
class Goods extends Model
{
    use SoftDeletes;

	protected $table = 'goods';

	static $status = [
		1 => '展示',
		0 => '不展示'
	];

	static $is_item = [
		1 => '是',
		0 => '否'
	];

    static $is_index = [
        1 => '是',
        0 => '否'
    ];

    static $top_recommended = [
        1 => '是',
        0 => '否'
    ];

    static $show_place = [
        1 => '热卖爆款',
        2 => '四季休闲',
        3 => '热销爆款',
        4 => '精品单鞋',
        5 => '优雅凉鞋',
        6 => '爆款短靴',
        7 => '性感鱼嘴鞋',
        8 => '马丁靴'
    ];

	static $cat = [
		1 => '单鞋',
	    2 => '短靴',
	    3 => '马丁靴',
	    4 => '休闲鞋'
	];

    static $is_long = [
        1 => '长图',
        0 => '方图'
    ];

    static $is_href = [
        1 => '跳转',
        0 => '不跳转'
    ];

	public function __construct()
	{
		parent::__construct();

		// 自动生成订单ID。
//		$this->attributes['id'] = uniqueid();
	}

	public static function boot()
	{
		parent::boot();

		static::creating(function ($model)
		{

		});
	}

	// 商品属性
	public function goods_attribute(){
		return $this->hasMany('App\Models\GoodsAttribute','goods_id');
	}

	// 商品图片
	public function pictures(){
		return $this->hasMany('App\Models\GoodsPicture','goods_id');
	}

	// 封面
	public function cover(){
		return $this->belongsTo('App\Models\UserFile','cover_id');
	}

    // 城市
//    public function getPictureUrlsAttribute(){
//        $pictures = $this->pictures;
//        $pictures_arr = [];
//        foreach ($pictures as $key=>$item){
//            $pictures_arr[] = route('FilePull', [
//                'id' => $item->picture_id
//            ]);
//        }
//        return $pictures_arr;
//    }

//    public function getCoverUrlAttribute(){
//        $url = route('FilePull', [
//                'id' => $this->cover_id
//            ]);
//        return $url;
//    }

    public function getPictureArrAttribute(){
        $pictures = $this->picture_urls;
        return explode(',',$pictures);
    }
}